using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Read.Services;
using Read.Utility;

namespace Read.Web.Controllers
{
    /// <summary>
    /// 测试页面
    /// </summary>
    public class TestController : BaseController
    {
        /// <summary>
        /// 测试时间转换
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public IActionResult Index(string t = "2017-09-16 22:14:36")
        {
            DateTime dt2 = Convert.ToDateTime(t);
            DateTime dt = new DateTime(1970, 1, 1);
            TimeSpan ts = dt.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string s = Convert.ToInt64(ts.TotalSeconds).ToString();
            return Content("t=2017-09-16 22:14:36\r\n" + "当前时间无格式化" + DateTime.Now.ToString() + " 当前时间戳" + Tools.ToUnixTime(DateTime.Now) + " 当前时间格式化之后" + Tools.FromUnixTime(Tools.ToUnixTime(DateTime.Now)).ToString("yyyy-MM-dd HH:mm:ss")
            + "\r\n输入的时间转系统" + dt2.ToString() + " 转为时间戳" + Tools.ToUnixTime(dt2) + " 再转为时间式化之后" + Tools.FromUnixTime(Tools.ToUnixTime(dt2)).ToString("yyyy-MM-dd HH:mm:ss"));
        }

        /// <summary>
        /// 文章明细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult Show(int id = 1)
        {
            var a = new ArchivesService();
            var archives = a.getArchives(id);
            ViewBag.Title = archives.Title;
            ViewBag.Count = archives.Content.Length;
            return View(archives);
        }

        /// <summary>
        /// 测试获取配置信息
        /// </summary>
        /// <returns></returns>
        public IActionResult Config()
        {
            return Content(ConfigService.WebName);
        }
    }
}